﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using System.Windows.Forms;

namespace MyWordAddIn
{
    /// <summary>
    /// 输出到列表
    /// </summary>
    //public class Message
    //{
    //    ListBox c;
    //    public Message(ListBox c)
    //    {
    //        this.c = c;
    //    }

    //    public void AddMsg(Word.Range r)
    //    {
    //        c.Items.Add(" Start:" + r.Start.ToString());
    //        c.Items.Add(" End:" + r.End.ToString());
    //        c.Items.Add(" Text:" + r.Text?.ToString());
    //    }

    //    public void AddMsg(string name,string val)
    //    {
    //        c.Items.Add(name+": " + val);
    //    }

    //    public void AddStyleMsg(Word.Range r)
    //    {
    //        c.Items.Add(" Start:" + r.Start.ToString());
    //        c.Items.Add(" End:" + r.End.ToString());
    //        c.Items.Add(" Text:" + r.Text?.ToString());
    //        Word.Style docStyle = ((Word.Style)r.get_Style());
    //        c.Items.Add(" style:" + docStyle.NameLocal);
    //        c.Items.Add(" baseStyle:" + ((Word.Style)docStyle.get_BaseStyle()).NameLocal);
    //    }

    //}

    public class Message
    {
        TextBox c;
        public Message(TextBox c)
        {
            this.c = c;
        }

        public void AddMsg(Word.Range r)
        {
            c.AppendText(" Start:" + r.Start.ToString()+Environment.NewLine);
            c.AppendText(" End:" + r.End.ToString() + Environment.NewLine);
            c.AppendText(" Text:" + r.Text?.ToString() + Environment.NewLine);
        }

        public void AddMsg(string text)
        {
            c.AppendText(text + Environment.NewLine);
        }

        public void AddMsg(string name, string val)
        {
            c.AppendText(name + ": " + val + Environment.NewLine);
        }

        public void AddListValueMsg(Word.Range r)
        {
            c.AppendText(" Start:" + r.Start.ToString() + Environment.NewLine);
            c.AppendText(" End:" + r.End.ToString() + Environment.NewLine);
            c.AppendText(" Text:" + r.Text?.ToString() + Environment.NewLine);
            c.AppendText(" ListValue:" + r.ListFormat.ListValue.ToString() + Environment.NewLine);
        }

        public void AddStyleMsg(Word.Range r)
        {
            c.AppendText(" Start:" + r.Start.ToString() + Environment.NewLine);
            c.AppendText(" End:" + r.End.ToString() + Environment.NewLine);
            c.AppendText(" Text:" + r.Text?.ToString() + Environment.NewLine);
            Word.Style docStyle = ((Word.Style)r.get_Style());
            c.AppendText(" style:" + docStyle.NameLocal + Environment.NewLine);
            c.AppendText(" baseStyle:" + ((Word.Style)docStyle.get_BaseStyle()).NameLocal + Environment.NewLine);
        }

        public void AddTemplateMsg(Word.Range r)
        {
            c.AppendText(" Start:" + r.Start.ToString() + Environment.NewLine);
            c.AppendText(" End:" + r.End.ToString() + Environment.NewLine);
            c.AppendText(" Text:" + r.Text?.ToString() + Environment.NewLine);
            Word.Style docStyle = ((Word.Style)r.get_Style());
            if (docStyle != null)
            {
                c.AppendText(" style:" + docStyle.NameLocal + Environment.NewLine);
                c.AppendText(" baseStyle:" + ((Word.Style)docStyle.get_BaseStyle()).NameLocal + Environment.NewLine);
            }
            c.AppendText(" templateName:" + r.ListFormat.ListTemplate?.Name+Environment.NewLine);
        }
    }
}
